package com;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Test extends HttpServlet{
	
	public Test() {
		super();
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		resp.setContentType("text/html");
		resp.setCharacterEncoding("utf-8");
		
		PrintWriter out = resp.getWriter();  //输出流
		//得到界面传过来的值
		String dcmpmethod = req.getParameter("dcmpmethod");
		
		String flog = req.getParameter("flog");
		
		if("0".equals(flog)){
			String username = req.getParameter("username");
			String password = req.getParameter("password");
			if("admin".equals(password)){
				req.setAttribute("username", username);
				System.out.println(username);
				req.getRequestDispatcher("index.jsp").forward(req, resp);
			}
		}else if("1".equals(flog)){
			if("ReloadEntity".equals(dcmpmethod)){
				out.println("<form id='form_btn_post' action='services/HttpCommandService?dcmpparam=dcmptool&dcmpmethod=ReloadEntity' method='post'  class='btn_form'>"
						+"<div class='btn_context'><textarea id='right_text' name='param' rows='10' cols='50' style='resize:none;'></textarea></div><br/>"
						+"<input id='btn' class='btn_context' type='button' onclick='textEntity()' name='btn' value='提交'>"
						+"</form>");
			}else if("DeleteEntity".equals(dcmpmethod)){
				out.println("<form id='form_btn_post' action='services/HttpCommandService?dcmpparam=dcmptool&dcmpmethod=DeleteEntity' method='post' class='btn_form'>"
						+"<div class='btn_context'><textarea id='right_text' name='param' rows='10' cols='50' style='resize:none;'></textarea></div><br/>"
						+"<input id='btn' class='btn_context' type='button' onclick='textEntity()' name='btn' value='提交'>"
						+"</form>");
			}else if("GetEntity".equals(dcmpmethod)){
				out.println("<form id='form_btn_post' action='services/HttpCommandService?dcmpparam=dcmptool&dcmpmethod=GetEntity' method='post' class='btn_form'>"
						+"<div class='btn_context'><input type='text' id='right_text' name='param'></div><br/>"
						+"<input id='btn' class='btn_context' type='button' onclick='inputEntity()' name='btn' value='提交'>"
						+"</form>");
			}
		}
		
	}

}
